package com.sscw.task.dao;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.guaike.core.mybatis.plugins.BaseDAO;
import com.sscw.task.entity.UAppUserEquityPO;
import com.sscw.task.mapper.UAppUserEquityExtMapper;
import com.sscw.task.mapper.UAppUserEquityMapper;
import lombok.AllArgsConstructor;
import org.springframework.stereotype.Repository;

import java.util.List;


@Repository
@AllArgsConstructor
public class UAppUserEquityDAO extends BaseDAO<UAppUserEquityMapper, UAppUserEquityPO> {

    private final UAppUserEquityExtMapper uAppUserEquityExtMapper;

    public int addPinecone(Long userId, Integer pinecone) {
        return uAppUserEquityExtMapper.addPinecone(userId, pinecone);
    }


    public int updatePineNut(Long userId, Integer pineNut) {
        return uAppUserEquityExtMapper.updatePineNut(userId, pineNut);
    }


    public List<UAppUserEquityPO> findTop20Pinecone() {
        LambdaQueryWrapper<UAppUserEquityPO> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.orderByDesc(UAppUserEquityPO::getPinecone);
        queryWrapper.last("limit 0,20");
        return getBaseMapper().selectList(queryWrapper);
    }

    public List<UAppUserEquityPO> findCurrMonthUngiveList(Integer month) {
        LambdaQueryWrapper<UAppUserEquityPO> lambdaQueryWrapper = new LambdaQueryWrapper<>();
        lambdaQueryWrapper.ne(UAppUserEquityPO::getCardGiveMonth, month);
        lambdaQueryWrapper.or(qw->qw.isNull(UAppUserEquityPO::getCardGiveMonth));
        lambdaQueryWrapper.orderByAsc(UAppUserEquityPO::getId);
        return getBaseMapper().selectList(lambdaQueryWrapper);
    }
}
